package liu.z;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;

import com.dutbbs.adapter.ListViewBaseAdaper;

public class IndexDir extends Activity
{
    private ListView listView;
    private Context context = this;
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.list_main);  
        listView = (ListView) this.findViewById(R.id.MyListView);
        MyViewListListener listener = new MyViewListListener();
        listView.setOnItemClickListener(listener);
        
        
        Bundle urlMap = getIntent().getExtras();
        List<Map<String,String>> listResult = new ArrayList<Map<String,String>>();
        for(String key:urlMap.keySet())
        {
            Map<String,String>m = new HashMap<String,String>();
            String url = urlMap.getString(key);
            m.put("title", key);
            m.put("info", url);
            listResult.add(m);
        }
        ListViewBaseAdaper adapter = new ListViewBaseAdaper(this, listResult);
        listView.setAdapter(adapter);
    }
    class MyViewListListener implements OnItemClickListener 
    {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id)
        {
            Intent in = new Intent(context, Index.class);
            @SuppressWarnings("unchecked")
            Map<String,String> itemMap = (Map<String, String>) listView.getItemAtPosition(position);
            in.putExtra("url", itemMap.get("info"));
            in.putExtra("title", itemMap.get("title"));
            startActivity(in);
        }
    };
}


